<<<<<<< HEAD
/*
 * @Author: your name
 * @Date: 2020-08-12 21:10:29
 * @LastEditTime: 2020-08-12 21:18:11
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \day01\demo9\main.go
 */
=======
>>>>>>> 4925e93374cf8c3a0dff85b9a22729f970dc1768
package main

import (
	"fmt"
<<<<<<< HEAD
	"io"
	"os"
)

func main() {
	file, err := os.Open("./main.go")
	defer file.Close()
	if err != nil {
		fmt.Println(err)
	}
	var tmp = make([]byte, 128)
	n, err := file.Read(tmp)
	if err == io.EOF {
		fmt.Println("文件读完了")
		return
	}
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(n)
	fmt.Println(tmp[:n])
=======
	"math/rand"
)

// 排序算法练习 简单的pass
// 堆排序
func heapSort(array []int) {
	m := len(array)
	s := m / 2
	for i := s; i > -1; i-- {
		heap(array, i, m-1)
	}
	for i := m - 1; i > 0; i-- {
		array[i], array[0] = array[0], array[i]
		heap(array, 0, i-1)
	}
}
func heap(array []int, i, end int) {
	l := 2*i + 1
	if l > end {
		return
	}
	n := l
	r := 2*i + 2
	if r <= end && array[r] > array[l] {
		n = r
	}
	if array[i] > array[n] {
		return
	}
	array[n], array[i] = array[i], array[n]
	heap(array, n, end)
}
func main() {
	s := make([]int, 0, 16)
	for i := 0; i < 16; i++ {
		s = append(s, rand.Intn(100))
	}
	fmt.Println(s)
	heapSort(s)
	fmt.Println(s)
>>>>>>> 4925e93374cf8c3a0dff85b9a22729f970dc1768
}
